package util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class ImgCount {
	public static int imgname(String path){
	 File file=new File(path);
	    try {
	    	if(!file.getParentFile().exists()){
	    		file.getParentFile().mkdirs();
	    	}
	    	if(!file.exists()){
	    		file.createNewFile();
	    	}
			FileReader fr=new FileReader(file);
			BufferedReader br=new BufferedReader(fr);
			String s=br.readLine();
			if(s==null){s="0";}
			br.close();
			fr.close();
			int a=0;
			try {
				a = Integer.parseInt(s);
				a++;
			} catch (NumberFormatException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			FileWriter fw=new FileWriter(file);
			BufferedWriter bw=new BufferedWriter(fw);
			bw.write(a+"");
			bw.close();
			fw.close();
			return a-1;
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return -1;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return -1;
		}
	}
}